package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.TitleDao;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Title;
import com.woniuxy.service.TitleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName TitleServceImpl
 * @Description TODO
 * @Author 冯浩波
 * @Date 2022/3/12 15:28
 */
@Service
public class TitleServceImpl implements TitleService {

    @Autowired(required = false)
    TitleDao titleDao;


    @Override
    public ResponseEntity deleteTitle(int id) {
        int res = titleDao.deleteTitle(id);
        if(res>0){
            return ResponseEntity.success("删除成功！");
        }else {
            return ResponseEntity.error("删除失败！");
        }
    }

    @Override
    public ResponseEntity addTitle(Title title) {
        int res = titleDao.addTitle(title);
        if(res>0){
            return ResponseEntity.success("添加成功！");
        }else {
            return ResponseEntity.error("添加失败！");
        }
    }

    @Override
    public ResponseEntity updateTitle(Title title) {
        int res = titleDao.updateTitle(title);
        if(res>0){
            return ResponseEntity.success("修改成功！");
        }else {
            return ResponseEntity.error("修改失败！");
        }
    }

    @Override
    public ResponseEntity findTitle(int currentPage, int pageSize,Title title) {
        //分页
        PageHelper.startPage(currentPage, pageSize);
        List<Title> titleList = titleDao.findTitle(title);
        PageInfo<Title> of = PageInfo.of(titleList);
        if(titleList.size()>0){
            return ResponseEntity.success("查询成功",of);
        }else {
            return ResponseEntity.error("查询失败");
        }

    }

    @Override
    public ResponseEntity findTopicID(int trainingid) {
        int topicid = titleDao.findTopicId(trainingid);
        return ResponseEntity.success("success",topicid);
    }

//    @Override
//    public ResponseEntity addTitle(TitleDto titleDto, int topicid) {
//        List<Title> list = new ArrayList();
//        list.add(titleDto.getTitle1());
//        list.add(titleDto.getTitle2());
//        list.add(titleDto.getTitle3());
//        list.add(titleDto.getTitle4());
//        list.add(titleDto.getTitle5());
//        list.add(titleDto.getTitle6());
//        list.add(titleDto.getTitle7());
//        list.add(titleDto.getTitle8());
//        list.add(titleDto.getTitle9());
//        list.add(titleDto.getTitle10());
//        for(Title title:list){
//            System.out.println(title);
//            title.setId(topicid);
//            titleDao.addTitle(title);
//        }
//        return ResponseEntity.success("success");
//    }
}
